let lc = window.localStorage

export default {
  setStorage(key,val) {
    lc[key] = JSON.stringify(val)
  },
  getStorage(key){
    if(lc[key]){
      return JSON.parse(lc[key])
    }else{
      return []
    }
  },
  getHistory(key){
    if(lc[key]){
      return JSON.parse(lc[key]).list
    }else{
      return []
    }
  },
  setHistory(key,val){
    let obj
    lc[key]?obj = JSON.parse(lc[key]):obj={list:[]}
    if(!obj.list.find(v=>v.value==val))obj.list.push({value:val})
    lc[key] = JSON.stringify(obj)
  }
}